/* 
 * Copyright 2009 The Tapestry-GAE team.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.tapestry.gae.jpa;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;

import org.springframework.dao.DataAccessException;
import org.springframework.orm.jpa.JpaCallback;
import org.springframework.orm.jpa.JpaDialect;
import org.springframework.transaction.annotation.Transactional;

import com.googlecode.tapestry.gae.model.PaginationList;
import com.googlecode.tapestry.gae.model.PaginationOptions;


/**
 * entity service interface
 * @author <a href="mailto:jun.tsai@gmail.com">Jun Tsai</a>
 * @since 0.1
 */
@SuppressWarnings("unchecked")
public interface EntityService {
	 public PaginationList paginate(final Class<?> persistClass,final Object conditions,
             final String order,final PaginationOptions options);
	public long count(Class<?> persistClass, Object conditions);
	public Iterator find(Class<?> persistClass, Object conditions, String order);
	public Iterator find(Class<?> persistClass, Object conditions,
			String order, int start, int offset) ;
	
	public abstract Object execute(JpaCallback action,
			boolean exposeNativeEntityManager) throws DataAccessException;

	public abstract Object execute(JpaCallback action)
			throws DataAccessException;

	public abstract List executeFind(JpaCallback action)
			throws DataAccessException;

	public abstract <T> T find(Class<T> entityClass, Object id)
			throws DataAccessException;

	public abstract List find(String queryString, Object... values)
			throws DataAccessException;

	public abstract List find(String queryString) throws DataAccessException;

	public abstract List findByNamedParams(String queryString,
			Map<String, ?> params) throws DataAccessException;

	public abstract List findByNamedQuery(String queryName, Object... values)
			throws DataAccessException;

	public abstract List findByNamedQuery(String queryName)
			throws DataAccessException;

	public abstract List findByNamedQueryAndNamedParams(String queryName,
			Map<String, ?> params) throws DataAccessException;

	public abstract void flush() throws DataAccessException;

	public abstract EntityManager getEntityManager();

	public abstract EntityManagerFactory getEntityManagerFactory();

	public abstract JpaDialect getJpaDialect();

	public abstract Map getJpaPropertyMap();

	public abstract <T> T getReference(Class<T> entityClass, Object id)
			throws DataAccessException;

	@Transactional
	public abstract <T> T merge(T entity) throws DataAccessException;

	@Transactional
	public abstract void persist(Object entity) throws DataAccessException;

	public abstract void refresh(Object entity) throws DataAccessException;

	@Transactional
	public abstract void remove(Object entity) throws DataAccessException;
}
